
var e = getApp(), t = e.requirejs("core"), a = e.requirejs("wxParse/wxParse"), i = e.requirejs("biz/diypage");
Page({
  data: {
    radioStatus:false,
    address:'',
    fenxiao:[
      { 'quyu': '省区', 'bind':'choseTxtColor'},
      { 'quyu': '市区', 'bind': 'choseTxtColor' },
      { 'quyu': '区/县', 'bind': 'choseTxtColor' }
    ],
    id:0,
    // 技师名字假数据
    // name: ['请选择分销区域', '省级分销', '市级分销', '区/县级分销'],
    index: 0,
  },
 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var e = this;
    t.get("member", {}, function (t) {
      0 != t.error ? wx.redirectTo({
        url: "/pages/message/auth/index"
      }) : e.setData({
        userInfo: t,
        name: t.nickname,
        phone: t.mobile
      })
    });
    t.get("member/index/getAbonusLevel", {}, function (t) {
      e.setData({
        levels:t
      })
    });
  },
  changeName:function(e){
    this.setData({ name: e.detail.value})
  },
  changePhone: function (e) {
    this.setData({ phone: e.detail.value })
  },
  changeAddress: function (e) {
    this.setData({ address: e.detail.value })
  },
  // 选择技师
  bindjishi: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  // 跳转申请后 状态
  toshenqingok: function () {
    var that = this, 
        name = this.data.name,
        phone = this.data.phone,
        address = this.data.address,
        levelId = this.data.levels[this.data.index].id,
        radioStatus = this.data.radioStatus,
        sendData = {
          name:name,
          phone: phone,
          address: address,
          levelId: levelId,
          user_id: this.data.userInfo.id
        };
        if(!name){
          wx.showToast({
            title: '请填写用户名',
          })
          return false
        } 
        if (!phone) {
          wx.showToast({
            title: '请填写用户电话',
          })
          return false
        } 
        if (!address) {
          wx.showToast({
            title: '请填写用户地址',
          })
          return false
        }
        if (!levelId) {
          wx.showToast({
            title: '请填写申请地区',
          })
          return false
        }
        if (!radioStatus) {
          wx.showToast({
            title: '请阅读申请协议',
          })
          return false
        }
        t.get("member/index/applyBecomeDis", sendData, function (e) {
          if(e==1){
            wx.navigateTo({
              url: '/pages/experts/ok/ok',
              success: function (res) { },
              fail: function (res) { },
              complete: function (res) { },
            })
          }else{
            wx.showToast({
              title: '网络繁忙',
            })
          }
        });    
  },
  // 跳转申请须知界面
  toagreement: function () {
    wx.navigateTo({
      url: '/pages/experts/agreement/agreement',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  choseTxtColor: function (e) {
    var id = e.currentTarget.dataset.id;  //获取自定义的ID值  
    this.setData({
      id: id
    })
  },  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  radioChange:function(){
    var radioStatus = this.data.radioStatus;
    this.setData({ radioStatus: !radioStatus})
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})